//
//  AEGoodsDetailRuleView.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/14.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEGoodsDetailRuleView.h"
#import "AE_Solar-Swift.h"
#import "AEGoodsDetailViewModel.h"

@interface AEGoodsDetailRuleView ()

@property (nonatomic, strong) AEGoodsDetailViewModel *viewModel;

/// 标题
@property (nonatomic, strong) UILabel *titleLabel;

/// 备注
@property (nonatomic, strong) UILabel *remarkLabel;

@property (nonatomic, strong) UIImageView *thumalImgView;


/// 标题
- (void)initWithTitleLabel;

/// 备注
- (void)initWithRemarkLabel;

@end

@implementation AEGoodsDetailRuleView

- (void)initWithSubView {
    [super initWithSubView];
    
    self.backgroundColor = kWhiteColor;
    
    /// 标题
    [self initWithTitleLabel];

    /// 备注
    [self initWithRemarkLabel];
}

/// 标题
- (void)initWithTitleLabel {
    if (!_titleLabel) {
        NSString *title = [AEStringExten localizedValueWithKey:@"兑换规则"];
        UIFont *font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
        float width = [title widthForFont:font] + 2;
        CGRect frame = CGRectMake(15, 12, width, 22);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:font propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#333333"];
            label.text = title;
        }];
    }
}

/// 备注
- (void)initWithRemarkLabel {
    if (!_remarkLabel) {
        NSString *title = [AEStringExten localizedValueWithKey:@"注意：本产品颜色随机发放，先到先得，兑完为止兑换后30天内发货"];
        UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
        float width = self.width - 30;
        float height = [title heightForFont:font width:width] + 2;
        CGRect frame = CGRectMake(15, self.titleLabel.bottom + 3, width, height);
        _remarkLabel = [UILabel createWithLabel:self frame:frame font:font propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#666666"];
            label.numberOfLines = 0;
            label.text = title;
        }];
    }
}

- (void)initWithThumalImgView {
    UIImage *defaultImg = [UIImage imageNamed:@"placeholder_image"];
    if (!_thumalImgView) {
        CGRect frame = CGRectMake(15, self.remarkLabel.bottom + 24, self.width - 30, 234);
        _thumalImgView = [UIImageView createWithImageView:self frame:frame defaultImage:defaultImg propertiesBlock:^(UIImageView * _Nonnull imageView) {
            imageView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
        }];
    }
    if (self.viewModel && self.viewModel.goodsInfoModel) {
        [_thumalImgView sd_setImageWithURL:[NSURL URLWithString:self.viewModel.goodsInfoModel.productImgUrl] placeholderImage:defaultImg];
    }
}

- (void)updateWithViewData:(id)data {
    self.viewModel = data;
    [self initWithThumalImgView];
}


@end
